﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Text;
using FizzBuzz.Properties;

namespace FizzBuzz
{
    [Table]
    public class Customers
    {
        [Column(IsPrimaryKey = true)]
        public int Id;
        [Column]
        public string Name;
    }

    class LinqRemoteQueriesDemo
    {
        // remote queries iterates over IQueryable
        // resolve to query operators in the Queryable class which emit expression trees
        // LINQ to SQL
        // LINQ to Entities
        // 
        public void Run()
        {
            Settings s = new Settings();
            DataContext dataContext = new DataContext(s.CustomerDataConnectionString);
            Table<Customers> customers = dataContext.GetTable<Customers>();

            var query = from c in customers
                                       where c.Name.Contains("a")
                                       orderby c.Name.Length
                                       select c.Name.ToUpper();

            foreach (string name in query) Console.WriteLine(name);

//            var query = from c in customers
//                                       where c.Name.Contains("a")
//                                       select c.Name.ToUpper();
//            IQueryable<string> query = from c in customers
//                                        select c.Name;
//
////            IEnumerable<string> query = customers.Where(n => n.Name.Contains("a"))
////                     .Select(n => n.Name.ToUpper());
//
//            foreach (string name in query)
//            {
//                Console.WriteLine("Name: {0}", name);
//            }
        }
    }
}
